<style lang="less">
    @import "../../../styles/table.less";
</style>
<template>
    <div class="search">
        <Row>
            <Col>
                <Card>

                    <Row class="operation">
                        <Button @click="add" type="primary" icon="md-add">新建会员</Button>
                        <Button @click="getDataList" icon="md-refresh">刷新</Button>
                        <circleLoading v-if="operationLoading"/>
                    </Row>
                    <!--<Row>
                        <Alert show-icon>
                            已选择 <span class="select-count">{{selectCount}}</span> 项
                            <a class="select-clear" @click="clearSelectAll">清空</a>
                        </Alert>
                    </Row>-->
                    <Row>
                        <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
                    </Row>
                    <Row type="flex" justify="end" class="page">
                        <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
                    </Row>
                </Card>
            </Col>
        </Row>

        <vip-type-drawer ref="vipTypeDrawer"></vip-type-drawer>
        <vip-price-drawer ref="vipPriceDrawer"></vip-price-drawer>


    </div>
</template>

<script>
    import circleLoading from "../../my-components/circle-loading.vue";
    import {add, edit, delByIds, list, get} from "@/api/vipType";
    import vipTypeDrawer from "./vipType-drawer";
    import VipPriceDrawer from "./vipPrice-drawer";

    export default {
        name: "viptype-manage",
        components: {
            VipPriceDrawer,
            circleLoading,
            vipTypeDrawer
        },
        data() {
            return {
                loading: false, // 表单加载状态
                operationLoading: false,
                drop: false,
                selectCount: 0, // 多选计数
                selectList: [], // 多选数据
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                searchForm: {
                    pageNumber: 1, // 当前页数
                    pageSize: 10, // 页面大小
                    sort: "createTime", // 默认排序字段
                    order: "desc", // 默认排序方式
                    studentName: "",
                    mobile: "",
                    startDate: "",
                    endDate: ""
                },
                selectDate: null, //选择日期绑定modal
                columns: [
                    /*{
                        type: "selection",
                        width: 60,
                        align: "center"
                    },*/
                    {
                        type: "index",
                        title: "序号",
                        width: 80,
                        align: "center"
                    },
                    {
                        title: "会员名称",
                        key: "vipName",
                        align: "center",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "会员编码",
                        key: "vipCode",
                        align: "center",
                        width: 120,
                        sortable: true
                    }, {
                        title: "更新时间",
                        key: "updateTime",
                        align: "center",
                        width: 180,
                        sortable: true
                    }, {
                        title: "操作",
                        key: "action",
                        width: 200,
                        align: "center",
                        fixed: "right",
                        render: (h, params) => {
                            return h("div", [
                                h(
                                    "Button",
                                    {
                                        props: {
                                            size: "small"
                                        },
                                        style: {
                                            marginRight: "5px"
                                        },
                                        on: {
                                            click: () => {
                                                this.edit(params.row);
                                            }
                                        }
                                    },
                                    "编辑"
                                ),
                                h(
                                    "Button",
                                    {
                                        props: {
                                            type: "primary",
                                            size: "small"
                                        },
                                        style: {
                                            marginRight: "5px"
                                        },
                                        on: {
                                            click: () => {
                                                this.setPrice(params.row);
                                            }
                                        }
                                    },
                                    "价格设置"
                                )
                                /* h(
                                     "Button",
                                     {
                                         props: {
                                             type: "error",
                                             size: "small"
                                         },
                                         on: {
                                             click: () => {
                                                 this.remove(params.row);
                                             }
                                         }
                                     },
                                     "删除"
                                 )*/
                            ]);
                        }
                    }],
                data: [], // 表单数据
                total: 0 // 表单数据总数
            }
        },
        methods: {
            init() {
                // this.getTreeData();
                this.getDataList();
            },
            getDataList() {
                this.loading = true;
                list(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.data = res.data.rows;
                        this.total = res.data.total;
                    }
                });
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getDataList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getDataList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getDataList();
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
            add() {
                let query = {type: 0}
                this.$refs.vipTypeDrawer.showDrawer(query);
            },
            edit(row) {
                let query = {id: row.id};
                this.$refs.vipTypeDrawer.showDrawer(query);
            },
            setPrice(row) {
                let query = {vipTypeId: row.id};
                this.$refs.vipPriceDrawer.showDrawer(query);
            },
            remove(row) {
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除?",
                    onOk: () => {
                        delByIds(row.id).then(res => {
                            if (res.status === true) {
                                this.$Message.success("删除成功");
                                this.getDataList();
                            }
                        });
                    }

                });
            },
            delAll() {

            }
        },
        mounted() {
            this.init();
        }
    }
</script>
